package dq.study.guava.collect;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author dongqun
 * @date 2019/12/20 14:30
 */
public class Collects {

    private static class User{
        String name;
        String sex;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }
    }

    public static void main(String[] args){
        User user1 = new User();
        user1.setName("sada");
        user1.setSex("123");
        User user2 = new User();
        user2.setName("sada");
        user2.setSex("9");
        List<User> users = new ArrayList<>();
        users.add(user1);
        users.add(user2);
        Map<String,User> map = users.stream().distinct().collect(Collectors.toMap(User::getName,user->user,(key1 , key2)-> key2));
        User user = map.get("sada");
        System.out.println(user.getName()+""+user.getSex());
    }
}
